var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0}), (o.TreasureChest = o.TreasureChestType = void 0);
var r,
    s = e("SDK"),
    c = e("AdUtils"),
    l = e("TreasureChestBox"),
    d = e("TreasureChestSmall"),
    u = cc._decorator,
    p = u.ccclass;
u.property,
    (function (e) {
        (e[(e.NINE = 0)] = "NINE"), (e[(e.ONE = 1)] = "ONE");
    })((r = o.TreasureChestType || (o.TreasureChestType = {})));
var h = (function (e) {
    function t() {
        var t = (null !== e && e.apply(this, arguments)) || this;
        return (
            (t.clickBtn_video = null),
            (t.progressBar = null),
            (t.skeleton = null),
            (t.view_Nine = null),
            (t.view_One = null),
            (t.nineTreasureChestArray = []),
            (t.callBack_One = null),
            (t.callBack_Nine = null),
            (t.clickCount = 0),
            (t.clickCount_Max = 2),
            (t.showCount = 0),
            (t._closeCb = null),
            (t.showBoxButton = !1),
            (t.isPlayAni = !1),
            (t._coin = 10),
            t
        );
    }
    return (
        __extends(t, e),
        (t.prototype.onLoad = function () {
            (this.view_Nine = this.node.getChildByName("view_Nine")),
                (this.view_One = this.node.getChildByName("view_One")),
                (this.clickBtn_video = this.view_One.getChildByName("clickBtn_video")),
                (this.skeleton = this.view_One.getChildByName("victorychest").getComponent(sp.Skeleton)),
                (this.progressBar = this.view_One.getChildByName("ProgressBar").getComponent(cc.ProgressBar)),
                (this.clickBtn_video.y = -cc.view.getVisibleSize().height / 2 + this.clickBtn_video.height / 2);
        }),
        (t.prototype.start = function () {}),
        (t.prototype.showButton = function () {
            this.view_Nine.getChildByName("tip_nine").active = !1;
            var e = this.view_Nine.getChildByName("bottun");
            e && (e.active = !0);
            var t = e.getChildByName("huang"),
                o = e.getChildByName("lv");
            this.lqEvent(o, t), l.TreasureChestBox.showBoxCount++;
        }),
        (t.prototype.lqEvent = function (e, t) {
            var o = this,
                n = e.getChildByName("lingqu"),
                i = t.getChildByName("quanbulingqu");
            (n.active = !0),
                (i.active = !0),
                e.on(
                    cc.Node.EventType.TOUCH_END,
                    function () {
                        s.default.Instance.showToast("奖励领取成功~~"), o.close();
                    },
                    this
                ),
                t.on(
                    cc.Node.EventType.TOUCH_END,
                    function () {
                        o.lookVideo();
                    },
                    this
                );
        }),
        (t.prototype.lookVideo = function () {
            var e = this;
            s.default.Instance.showRewardVideo(
                function () {
                    console.log("视频播放成功"),
                        s.default.Instance.showToast("双倍奖励领取成功~~"),
                        e.doubleReward(),
                        e.close();
                },
                function () {
                    s.default.Instance.showToast("看完视频才能领取奖励哦~~");
                },
                function () {
                    s.default.Instance.showToast("暂无广告");
                }
            );
        }),
        (t.prototype.doubleReward = function () {
            this.nineTreasureChestArray.forEach(function (e) {
                var t = e.getComponent(d.TreasureChestSmall);
                t && t.getReward();
            });
        }),
        (t.prototype.close = function () {
            this._closeCb && (this._closeCb(), (this._closeCb = null)), this.closeView(), this.node.destroy();
        }),
        (t.prototype.showView = function (e, t, o, n) {
            switch (
                (void 0 === o && (o = null),
                void 0 === n && (n = null),
                (this._data = n),
                this.clickBtn_video.on(cc.Node.EventType.TOUCH_END, this.onClickVideoBtn, this),
                (this._closeCb = o),
                e)
            ) {
                case r.NINE:
                    this.showNineView(), (this.callBack_Nine = t);
                    break;
                case r.ONE:
                    if (
                        (this.showOneView(),
                        (this.callBack_One = t),
                        console.log("diamondsData:", this._data),
                        console.log("diamondsData:", this._data.type),
                        this._data)
                    )
                        if ((e = this._data.type) == l.TreasureBox.COIN) {
                            var i = this._data.coin;
                            this.initRewardData(i);
                        } else if (e == l.TreasureBox.DIAMONDS) {
                            var a = this._data.coin;
                            this.initRewardData(a);
                        } else if (e == l.TreasureBox.RADOM) {
                            var s = c.default.instance.getRandomInt(1, 2);
                            s == l.TreasureBox.COIN
                                ? ((i = this._data.coin), this.initRewardData(i))
                                : s == l.TreasureBox.DIAMONDS && ((a = this._data.coin), this.initRewardData(a));
                        }
            }
        }),
        (t.prototype.showOneView = function () {
            (this.view_One.active = !0),
                s.default.Instance.hideBanner(),
                this.view_One.getChildByName("tip_one"),
                this.schedule(this.updateProgressBar, 0.1);
        }),
        (t.prototype.showNineView = function () {
            (this.view_Nine.active = !0),
                this.view_One.getChildByName("tip_nine"),
                (this.nineTreasureChestArray = this.view_Nine.getChildByName("nine").children);
            for (var e = 0; e < this.nineTreasureChestArray.length; e++) {
                var t = this.nineTreasureChestArray[e].addComponent(d.TreasureChestSmall);
                t.init(this._data), t.node.on(cc.Node.EventType.TOUCH_END, this.onVideoClick, this);
            }
        }),
        (t.prototype.setTipNodeScale = function () {}),
        (t.prototype.onVideoClick = function (e) {
            console.log("点击事件:", e.currentTarget.name), (this.isPlayAni = !0);
            var t = e.currentTarget.getChildByName("bg").getChildByName("victorychest"),
                o = e.currentTarget.getComponent(d.TreasureChestSmall),
                n = t.getComponent(sp.Skeleton);
            if (o.isClick) {
                if (
                    (console.log("点击的 视频箱子：", o.getVider_icon()),
                    o.getVider_icon() || n.setAnimation(0, "open_first", !1),
                    (this.clickCount += 1),
                    o.video_Ok(this.callBack_Nine),
                    "open_first" == n.animation && this.clickCount >= this.clickCount_Max)
                ) {
                    if (this.showBoxButton) return;
                    (this.showBoxButton = !0), this.showButton();
                    for (var i = 0; i < this.nineTreasureChestArray.length; i++)
                        this.nineTreasureChestArray[i].getComponent(d.TreasureChestSmall).setVider_icon();
                }
                n.setCompleteListener(function () {});
            }
        }),
        (t.prototype.onClickVideoBtn = function () {
            this.progressBar.progress >= 1 || this.setProgressBar();
        }),
        (t.prototype.initRewardData = function (e) {
            var t = this;
            if (e) {
                c.default.instance.loadPrefabs(e.res, function (e) {
                    t.view_One
                        .getChildByName("reward")
                        .getChildByName("img_zuanshi2")
                        .getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(e);
                });
                var o = this.view_One.getChildByName("reward").getChildByName("New Label").getComponent(cc.Label);
                (this._coin = c.default.instance.getRandomInt(e.min, e.max)), (o.string = "" + this._coin);
            }
        }),
        (t.prototype.setProgressBar = function () {
            var e = this;
            (this.progressBar.progress += 0.15), this.progressBar.progress > 0.8 && s.default.Instance.showBanner();
            var t = l.TreasureBox.COIN;
            this.progressBar.progress >= 1 &&
                ((this.view_One.getChildByName("reward").active = !0),
                this.callBack_One(t, this._coin),
                this.skeleton.setAnimation(0, "open_first", !1),
                this.closeSchedule(),
                this.scheduleOnce(function () {
                    (e.view_One.active = !1),
                        e._closeCb && (e._closeCb(), (e._closeCb = null)),
                        e.node.removeFromParent(),
                        e.node.destroy();
                }, 2));
        }),
        (t.prototype.closeSchedule = function () {
            this.unschedule(this.updateProgressBar);
        }),
        (t.prototype.updateProgressBar = function () {
            this.progressBar.progress > 0 && (this.progressBar.progress -= 0.08);
        }),
        (t.prototype.closeView = function () {
            if (
                ((this.view_Nine.active = !1),
                (this.view_One.active = !1),
                (this.clickCount = 0),
                this.nineTreasureChestArray.length > 0)
            )
                for (var e = 0; e < this.nineTreasureChestArray.length; e++)
                    this.nineTreasureChestArray[e].getComponent(d.TreasureChestSmall).close();
        }),
        __decorate([p("TreasureChest")], t)
    );
})(cc.Component);
o.TreasureChest = h;
